package com.mxgraph.examples.swing.editor;

import java.io.ObjectInputStream.GetField;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;

public class DatabaseConnectivity {
	 	static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
	   static final String DB_URL = "jdbc:mysql://localhost/pf";
	   //  Database credentials
	   static final String USER = "root";
	   static final String PASSWORD = "";
	  // Statement sql;
	   public static Statement stmt = null;
	   public static Statement generateStatement(){
		   
	   Connection conn = null;
	   
	  // String sql1 = null;
	   //sql1=sql;
	   
	   try{
	      //STEP 2: Register JDBC driver
	      Class.forName("com.mysql.jdbc.Driver");
	      
	      
	      //STEP 3: Open a connection
	     // System.out.println("Connecting to database...");
	      conn = DriverManager.getConnection(DB_URL,USER,PASSWORD);
	 
	   // System.out.println("Connecting to database...");
	     // System.out.println("Creating statement...");
	      stmt = conn.createStatement();
   
	      //System.out.println("2");
	           
	   }catch(Exception e){
		      //Handle errors for Class.forName
               //JOptionPane.ERROR_MESSAGE(null,"asd");
               JOptionPane.showMessageDialog(null, "<html><font color=\"red\">Database Connectivity is not done.<br>Make necessary changes in DatabaseConnectivity.java file.</font></html>","Database Connectivity",JOptionPane.ERROR_MESSAGE);
               //int confirmed = JOptionPane.showConfirmDialog(null,"Database Connectivity is not done./nMake necessary changes in DatabaseConnectivity.java file.","Databse Connectivity",
		//			 JOptionPane.ERROR_MESSAGE);
               e.printStackTrace();
		System.exit(0);      
               //e.printStackTrace();
		   }finally{
		  
		   }//end try
		//   System.out.println("Goodbye!");
		   
		return stmt;
		
	   
	   }
	   

}
